package com.src.myapplication.utils;

import android.support.v4.app.Fragment;
import android.util.SparseArray;

import com.src.myapplication.ui.view.fragmentzhibo.CaiYi;
import com.src.myapplication.ui.view.fragmentzhibo.FuJin;
import com.src.myapplication.ui.view.fragmentzhibo.GuanZhu;
import com.src.myapplication.ui.view.fragmentzhibo.MingXing;
import com.src.myapplication.ui.view.fragmentzhibo.Remen;
import com.src.myapplication.ui.view.fragmentzhibo.TuiJian;
import com.src.myapplication.ui.view.fragmentzhibo.XinRen;

/**
 * 类描述:
 * 创建人:
 * 创建时间:2016/10/11
 * 备注:fragment工厂
 */
public class FragmentFactory {

    private static final int FRAGMENT_Min0 = 0;
    private static final int FRAGMENT_Min1 = 1;
    private static final int FRAGMENT_Min2 = 2;
    private static final int FRAGMENT_Min3 = 3;
    private static final int FRAGMENT_Min4 = 4;
    private static final int FRAGMENT_Min5 = 5;
    private static final int FRAGMENT_Min6 = 6;

    //SparseArray:key是整形的key,根据整形的key来获取一个对象,效率比较高.
    public static SparseArray<Fragment> fragments = new SparseArray<>();
    public static SparseArray<Fragment> fragments_pengyou = new SparseArray<>();

    //创建一个工厂方法,用来创建一个Fragment对象
    public static Fragment createFragment(int index) {
        //从集合中获取
        Fragment fragment = fragments.get(index);
        if (fragment == null) {
            switch (index) {
                case FRAGMENT_Min0:
                    fragment = new TuiJian();
                    break;
                case FRAGMENT_Min1:
                    fragment = new Remen();
                    break;
                case FRAGMENT_Min2:
                    fragment = new GuanZhu();
                    break;
                case FRAGMENT_Min3:
                    fragment = new XinRen();
                    break;
                case FRAGMENT_Min4:
                    fragment = new FuJin();
                    break;
                case FRAGMENT_Min5:
                    fragment = new MingXing();
                    break;
                case FRAGMENT_Min6:
                    fragment = new CaiYi();
                    break;
            }
            //存到集合中
            fragments.put(index, fragment);
        }

        return fragment;
    }


}
